package craky.keeper.skin;

import java.awt.Image;

import javax.swing.ImageIcon;

import craky.keeper.KeeperConst;
import craky.keeper.util.KeeperUtil;

public class Skin
{
  private String name;
  private boolean selected;
  private Boolean isDefault;
  private SkinUnit unit;

  public Skin(String name)
  {
    this.name = name;
  }

  public Image getImage()
  {
    return isDefault() ? null : 
      new ImageIcon(KeeperConst.SKIN_DIR + KeeperConst.FILE_SEP + this.name + 
      KeeperConst.FILE_SEP + "normal.png").getImage();
  }

  public Image getBlurImage()
  {
    return isDefault() ? null : 
      new ImageIcon(KeeperConst.SKIN_DIR + KeeperConst.FILE_SEP + this.name + 
      KeeperConst.FILE_SEP + "blur.png").getImage();
  }

  public Image getPreviewImage()
  {
    return isDefault() ? KeeperUtil.getImage("default_skin_preview.png") : 
      new ImageIcon(KeeperConst.SKIN_DIR + 
      KeeperConst.FILE_SEP + this.name + KeeperConst.FILE_SEP + "preview.png").getImage();
  }

  public String getName()
  {
    return this.name;
  }

  public boolean isSelected()
  {
    return this.selected;
  }

  public void setSelected(boolean selected)
  {
    this.selected = selected;
    this.unit.repaint();
  }

  public SkinUnit getUnit()
  {
    return this.unit;
  }

  public void setUnit(SkinUnit unit)
  {
    this.unit = unit;
  }

  public boolean isDefault()
  {
    if (this.isDefault == null)
    {
      this.isDefault = Boolean.valueOf(this.name.equals("默认皮肤"));
    }

    return this.isDefault.booleanValue();
  }

  @Override
public String toString()
  {
    return this.name;
  }
}